package com.kylin.common.weixin.mp.api;

import com.alibaba.fastjson2.JSONObject;
import com.kylin.common.weixin.util.WxRequest;
import org.apache.commons.lang3.StringUtils;

/**
 * 消息推送接口
 * @author wuhao
 * @version 1.0 - 2023/6/6
 */
public class MessageService {

    /**
     * 主动回复
     */
    private static final String MESSAGE_CUSTOM_SEND_URL = "/cgi-bin/message/custom/send";


    /**
     * 主动回复消息
     * @param appid 公众号的唯一标识
     * @param message 消息内容
     * @return eg.{"access_token":"ACCESS_TOKEN","expires_in":7200}
     * @version 1.0  by wuhao at 2019-03-04
     */
    public static JSONObject sendMessage(JSONObject message, String appid){
        String url = MESSAGE_CUSTOM_SEND_URL;
        if(StringUtils.isNotBlank(appid)) {
            url += "?from_appid=" + appid;
        }
        return WxRequest.post(url, message.toJSONString());
    }
}
